/**
 * Copyright (C) 2019 Baidu, Inc. All Rights Reserved.
 */
package com.bailiban.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author zhulang
 * @version 创建时间：2019年10月9日 上午11:57:49
 */
public class JedisPoolUtil {
    private static JedisPool jedisPool;

    static {
        InputStream inputStream = JedisPoolUtil.class.getClassLoader().getResourceAsStream("jedis.properties");
        Properties properties = new Properties();
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(Integer.parseInt(properties.getProperty("maxIdle")));
        config.setMaxTotal(Integer.parseInt(properties.getProperty("maxTotal")));
        jedisPool =
                new JedisPool(config, properties.getProperty("host"), Integer.parseInt(properties.getProperty("port")),
                        Integer.parseInt(properties.getProperty("timeOut")), properties.getProperty("password"));
    }

    public static Jedis getJedis() {
        return jedisPool.getResource();

    }

}
